uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026

Warning

uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.

Response = [ErrorHandlerResponse]

Property

Product: 

Class: 

Determines the engine's behavior after an error handler callback finishes executing.

Remarks

The Response property is the primary control mechanism used inside an AddErrorHandler callback to dictate the flow of execution after an error has been intercepted. It determines whether the engine should abort the operation, attempt to recover and continue, or delegate the error to another handler in the chain.

This method can only be called from within an error handler's callback function.


⚙️ Handler Responses

You must provide a value from the ErrorHandlerResponse enum:

  • ErrorHandlerResponse::Abort (Default)This is the standard behavior. It immediately halts the parsing or evaluation process. The original function call (e.g., EvalStr) will fail and return an error message. Use this when the error is unrecoverable.

  • ErrorHandlerResponse::ResumeThis powerful option instructs the uCalc engine to continue execution from where it left off, as if the error never occurred. This is ideal for creating robust, fault-tolerant applications that can recover from invalid input.

    ⚠️ Important: Before resuming, your handler must resolve the condition that caused the error. For example, if the error was Undefined_Identifier, you might define the variable. Failure to resolve the issue will likely cause an infinite loop as the engine repeatedly encounters the same error.

  • ErrorHandlerResponse::ReRaiseThis passes the current error to the next handler in the stack. It allows for creating layered or tiered error-handling strategies. For instance, an initial handler might simply log all errors and then ReRaise them, allowing a more specific, subsequent handler to decide whether to Abort or Resume.


Comparative Analysis

  • vs. Traditional try-catchStandard exception handling in languages like C# and C++ is primarily about unwinding the stack and aborting a block of code. try-catch provides a way to fail gracefully. uCalc's model, particularly with Resume, offers a fundamentally different paradigm: error recovery. It allows an operation to be repaired and continued, which is essential for interactive applications, live editors, or long-running calculations where simply aborting is not desirable.

  • vs. LISP Condition SystemThe combination of intercepting an error, choosing a recovery strategy (Resume), and delegating responsibility (ReRaise) is conceptually similar to the highly-regarded Common Lisp Condition System. This system separates the act of signaling an error from the logic that handles it, providing a level of flexibility rarely seen outside of Lisp-like languages. This makes uCalc's error handling exceptionally powerful for complex parsing and evaluation tasks.

Examples

Practical: Creates a robust error handler that automatically defines variables on-the-fly when an 'Undefined Identifier' error occurs.

ID: 329

				
					using uCalcSoftware;

var uc = new uCalc();

// This error handler allows you to use variables that were not
// explicitly defined previously by defining unrecognized identifiers
// as variables instead of returning an error.
static void AutoVariableDef(Handle_uCalc h) {
   var uc = new uCalc(h);
   if (uc.Error.Code == ErrorCode.Undefined_Identifier) {
      uc.DefineVariable(uc.Error.Symbol);
      uc.Error.Response = ErrorHandlerResponse.Resume;
   }
}


uc.Error.AddHandler(AutoVariableDef);
// The handler will automatically define 'AutoTest' on first use.
Console.WriteLine(uc.Eval("AutoTest = 123"));
Console.WriteLine(uc.Eval("AutoTest * 1000"));
				
			
123
123000
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

// This error handler allows you to use variables that were not
// explicitly defined previously by defining unrecognized identifiers
// as variables instead of returning an error.
void ucalc_call AutoVariableDef(Handle_uCalc h) {
   auto uc = uCalc(h);
   if (uc.Error().Code() == ErrorCode::Undefined_Identifier) {
      uc.DefineVariable(uc.Error().Symbol());
      uc.Error().Response(ErrorHandlerResponse::Resume);
   }
}

int main() {
   uCalc uc;
   uc.Error().AddHandler(AutoVariableDef);
   // The handler will automatically define 'AutoTest' on first use.
   cout << uc.Eval("AutoTest = 123") << endl;
   cout << uc.Eval("AutoTest * 1000") << endl;
}
				
			
123
123000
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   '// This error handler allows you to use variables that were not
   '// explicitly defined previously by defining unrecognized identifiers
   '// as variables instead of returning an error.
   Public Sub AutoVariableDef(ByVal h As Handle_uCalc)
      Dim uc As New uCalc(h)
      If uc.Error.Code = ErrorCode.Undefined_Identifier Then
         uc.DefineVariable(uc.Error.Symbol)
         uc.Error.Response = ErrorHandlerResponse.Resume
      End If
   End Sub
   
   Public Sub Main()
      Dim uc As New uCalc()
      uc.Error.AddHandler(AddressOf AutoVariableDef)
      '// The handler will automatically define 'AutoTest' on first use.
      Console.WriteLine(uc.Eval("AutoTest = 123"))
      Console.WriteLine(uc.Eval("AutoTest * 1000"))
   End Sub
End Module
				
			
123
123000
Error handler to auto-define variables

ID: 54

				
					using uCalcSoftware;

var uc = new uCalc();

// This error handler allows you to use variables that were not
// explicitly defined previously, by defining the unrecognized identifiers
// as variables instead of returning an error
static void AutoVariableDef(Handle_uCalc h) {
   var uc = new uCalc(h);
   if (uc.Error.Code == ErrorCode.Undefined_Identifier) {
      uc.DefineVariable(uc.Error.Symbol);
      uc.Error.Response = ErrorHandlerResponse.Resume;
   }
}


uc.Error.AddHandler(AutoVariableDef);
Console.WriteLine(uc.Eval("AutoTest = 123"));
Console.WriteLine(uc.Eval("AutoTest * 1000"));
				
			
123
123000
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

// This error handler allows you to use variables that were not
// explicitly defined previously, by defining the unrecognized identifiers
// as variables instead of returning an error
void ucalc_call AutoVariableDef(Handle_uCalc h) {
   auto uc = uCalc(h);
   if (uc.Error().Code() == ErrorCode::Undefined_Identifier) {
      uc.DefineVariable(uc.Error().Symbol());
      uc.Error().Response(ErrorHandlerResponse::Resume);
   }
}

int main() {
   uCalc uc;
   uc.Error().AddHandler(AutoVariableDef);
   cout << uc.Eval("AutoTest = 123") << endl;
   cout << uc.Eval("AutoTest * 1000") << endl;
}
				
			
123
123000
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   '// This error handler allows you to use variables that were not
   '// explicitly defined previously, by defining the unrecognized identifiers
   '// as variables instead of returning an error
   Public Sub AutoVariableDef(ByVal h As Handle_uCalc)
      Dim uc As New uCalc(h)
      If uc.Error.Code = ErrorCode.Undefined_Identifier Then
         uc.DefineVariable(uc.Error.Symbol)
         uc.Error.Response = ErrorHandlerResponse.Resume
      End If
   End Sub
   
   Public Sub Main()
      Dim uc As New uCalc()
      uc.Error.AddHandler(AddressOf AutoVariableDef)
      Console.WriteLine(uc.Eval("AutoTest = 123"))
      Console.WriteLine(uc.Eval("AutoTest * 1000"))
   End Sub
End Module
				
			
123
123000
A practical example of a proactive error handler that automatically defines undeclared variables on the fly, allowing the expression to successfully resume execution.

ID: 1190

				
					using uCalcSoftware;

var uc = new uCalc();

// This handler automatically defines variables when they are first used.
static void AutoDefineHandler(Handle_uCalc h) {
   var uc = new uCalc(h);
   // Check if the error is specifically an undefined identifier
   if (uc.Error.Code == ErrorCode.Undefined_Identifier) {
      Console.WriteLine($"Handler: '{uc.Error.Symbol}' is undefined. Defining it now.");
      uc.DefineVariable(uc.Error.Symbol);

      // Tell the engine to resume the operation
      uc.Error.Response = ErrorHandlerResponse.Resume;
   }
}


uc.Error.AddHandler(AutoDefineHandler);

// 'my_var' doesn't exist yet, but the handler will create it.
var result = uc.EvalStr("my_var = 100; my_var = my_var * 2");

Console.WriteLine($"Final result: {result}");
				
			
Handler: 'my_var' is undefined. Defining it now.
Final result: 200
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

// This handler automatically defines variables when they are first used.
void ucalc_call AutoDefineHandler(Handle_uCalc h) {
   auto uc = uCalc(h);
   // Check if the error is specifically an undefined identifier
   if (uc.Error().Code() == ErrorCode::Undefined_Identifier) {
      cout << "Handler: '" << uc.Error().Symbol() << "' is undefined. Defining it now." << endl;
      uc.DefineVariable(uc.Error().Symbol());

      // Tell the engine to resume the operation
      uc.Error().Response(ErrorHandlerResponse::Resume);
   }
}

int main() {
   uCalc uc;
   uc.Error().AddHandler(AutoDefineHandler);

   // 'my_var' doesn't exist yet, but the handler will create it.
   auto result = uc.EvalStr("my_var = 100; my_var = my_var * 2");

   cout << "Final result: " << result << endl;
}
				
			
Handler: 'my_var' is undefined. Defining it now.
Final result: 200
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   '// This handler automatically defines variables when they are first used.
   Public Sub AutoDefineHandler(ByVal h As Handle_uCalc)
      Dim uc As New uCalc(h)
      '// Check if the error is specifically an undefined identifier
      If uc.Error.Code = ErrorCode.Undefined_Identifier Then
         Console.WriteLine($"Handler: '{uc.Error.Symbol}' is undefined. Defining it now.")
         uc.DefineVariable(uc.Error.Symbol)
         
         '// Tell the engine to resume the operation
         uc.Error.Response = ErrorHandlerResponse.Resume
      End If
   End Sub
   
   Public Sub Main()
      Dim uc As New uCalc()
      uc.Error.AddHandler(AddressOf AutoDefineHandler)
      
      '// 'my_var' doesn't exist yet, but the handler will create it.
      Dim result = uc.EvalStr("my_var = 100; my_var = my_var * 2")
      
      Console.WriteLine($"Final result: {result}")
   End Sub
End Module
				
			
Handler: 'my_var' is undefined. Defining it now.
Final result: 200